package DiDi;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Description：
 * Author: zhangc
 * Date：2017/9/24 9:06
 */
public class ThreadLocalTest {

    private static ExecutorService service = Executors.newFixedThreadPool(10);
    private static final ThreadLocal<Integer> local = new ThreadLocal<Integer>() {
        @Override
        protected Integer initialValue() {
            return 0;
        }
    };

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            service.execute(new MyTh());
        }
        service.shutdown();
    }


    static class MyTh implements Runnable {

        @Override
        public void run() {
            local.set(local.get() + 1);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(local.get());
        }
    }

}
